package cn.sfrog.project.biz.admin.controller;

import cn.sfrog.common.annotation.Log;
import cn.sfrog.common.annotation.RepeatSubmit;
import cn.sfrog.common.core.controller.BaseController;
import cn.sfrog.common.core.domain.AjaxResult;
import cn.sfrog.common.core.page.TableDataInfo;
import cn.sfrog.common.enums.BusinessType;
import cn.sfrog.common.utils.poi.ExcelUtil;
import cn.sfrog.project.biz.admin.domain.vo.BizDoctorBindingAccountFormVO;
import cn.sfrog.project.biz.admin.domain.vo.BizDoctorFormVO;
import cn.sfrog.project.biz.admin.domain.vo.BizDoctorQueryVO;
import cn.sfrog.project.biz.admin.domain.vo.BizDoctorVO;
import cn.sfrog.project.biz.admin.service.IBizDoctorService;
import cn.sfrog.system.domain.vo.BizStatusChangeVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.List;


@Api(tags = "管理后台-医生相关")
@RestController
@RequestMapping("/biz/doctor")
public class BizDoctorController extends BaseController {
    @Resource
    private IBizDoctorService bizDoctorService;

    /**
     * 查询医生列表
     */
    @ApiOperation("查询列表")
    @PreAuthorize("@ss.hasPermi('biz:doctor:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizDoctorQueryVO queryVO) {
        startPage();
        List<BizDoctorVO> list = bizDoctorService.selectBizDoctorList(queryVO);
        return getDataTable(list);
    }

    /**
     * 查询医院下所有的医生-分页
     */
    @ApiOperation("查询医院下所有的医生-分页")
    @GetMapping("/getAllDoctorPageByHospital")
    public TableDataInfo getAllDoctorPageByHospital(BizDoctorQueryVO queryVO) {
        startPage();
        List<BizDoctorVO> list = bizDoctorService.selectBizDoctorList(queryVO);
        return getDataTable(list);
    }


    /**
     * 导出医生列表
     */
    @ApiOperation("导出")
    @PreAuthorize("@ss.hasPermi('biz:doctor:export')")
    @Log(title = "医生", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BizDoctorQueryVO query) {
        List<BizDoctorVO> list = bizDoctorService.selectBizDoctorList(query);
        ExcelUtil<BizDoctorVO> util = new ExcelUtil<BizDoctorVO>(BizDoctorVO.class);
        util.exportExcel(response, list, "医生数据");
    }

    /**
     * 获取医生详细信息
     */
    @ApiOperation("获取详情")
    @PreAuthorize("@ss.hasPermi('biz:doctor:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(bizDoctorService.selectBizDoctorById(id));
    }

    /**
     * 新增医生
     */
    @ApiOperation("新增")
    @RepeatSubmit
    @PreAuthorize("@ss.hasPermi('biz:doctor:add')")
    @Log(title = "医生", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizDoctorFormVO form) {
        return toAjax(bizDoctorService.insertBizDoctor(form));
    }

    /**
     * 修改医生
     */
    @ApiOperation("修改")
    @RepeatSubmit
    @PreAuthorize("@ss.hasPermi('biz:doctor:edit')")
    @Log(title = "医生", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizDoctorFormVO form) {
        return toAjax(bizDoctorService.updateBizDoctor(form));
    }

    /**
     * 删除医生
     */
    @ApiOperation("删除")
    @PreAuthorize("@ss.hasPermi('biz:doctor:remove')")
    @Log(title = "医生", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(bizDoctorService.deleteBizDoctorByIds(ids));
    }

    /**
     * 更改状态医生
     */
    @ApiOperation("更改状态")
    @PreAuthorize("@ss.hasAnyPermi('biz:doctor:changeStatus,biz:doctor:changeStatusBatch')")
    @Log(title = "医生", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public AjaxResult changeStatus(@RequestBody @Valid BizStatusChangeVO vo) {
        return AjaxResult.success(bizDoctorService.changeStatus(vo));
    }

    @ApiOperation("绑定账号")
    @PreAuthorize("@ss.hasPermi('biz:doctor:bindingUserAccount')")
    @Log(title = "医生", businessType = BusinessType.UPDATE)
    @PostMapping("/bindingUserAccount")
    public AjaxResult bindingUserAccount(@RequestBody @Valid BizDoctorBindingAccountFormVO formVO){
        return AjaxResult.success(bizDoctorService.bindingUserAccount(formVO));
    }
}
